import { defHttp, jsonHttp } from '@/utils/http/axios';
import {
  LoginParams,
  detailParams,
  queryAllParams,
  noteDetailParams,
  LoginResultModel,
  GetUserInfoModel,
  saveParams,
} from './model/userModel';
import { BasicListResult, BasicDataResult } from '../model/baseModel';

import { ErrorMessageMode } from '#/axios';
import { listParams } from '@/api/sys/model/clazzModel';
import { bookDetailParams } from '@/api/sys/model/bookModel';

enum Api {
  //Login = '/login',
  Login = '/jz/wm/userLogin/login',
  Logout = '/jz/wm/userLogin/logout',
  GetUserInfo = '/jz/wm/userInfo/getUserInfo',
  getIsLogin = '/jz/wm/userInfo/getIsLogin',
  GetPermCode = '/getPermCode',
  TestRetry = '/testRetry',
  list = '/jz/wm/userManage/list',
  userLists = '/jz/wm/userManage/userLists',
  detail = '/jz/wm/userManage/detail',
  save = '/jz/wm/userManage/save',
  up = '/jz/wm/userManage/up',
  down = '/jz/wm/userManage/down',
  queryAll = '/jz/sys/userManage/queryAll',
  importExcel = '/jz/sys/userManage/importExcel',
  userNoteList = '/jz/sys/userManage/userNoteList',
  userNoteDetail = '/jz/sys/userManage/userNoteDetail',
  upPassWord = '/jz/wm/userManage/upPassWord',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function listApi(params: listParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicListResult>(
    {
      url: Api.list,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
export function userListsApi(params: listParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicListResult>(
    {
      url: Api.userLists,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function queryAllApi(params: queryAllParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.queryAll,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function getIsLoginApi(params: null, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.getIsLogin,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function detailApi(params: detailParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.detail,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function saveApi(params: saveParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.save,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function importExcelApi(params: saveParams, mode: ErrorMessageMode = 'modal') {
  // jsonHttp defHttp
  return jsonHttp.post<BasicDataResult>(
    {
      url: Api.importExcel,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function userNoteListApi(params: listParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicListResult>(
    {
      url: Api.userNoteList,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function userNoteDetailApi(params: noteDetailParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.userNoteDetail,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.post<BasicDataResult>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  return defHttp.post({ url: Api.Logout });
}

export function testRetry() {
  return defHttp.get(
    { url: Api.TestRetry },
    {
      retryRequest: {
        isOpenRetry: true,
        count: 5,
        waitTime: 1000,
      },
    },
  );
}

export function upApi(params: bookDetailParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.up,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function downApi(params: bookDetailParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.down,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}


export function upPassWordApi(params: bookDetailParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.upPassWord,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
